﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.IoC.Configuration.Interfaces;
using LinFu.IoC.Interfaces;
using LinFu.IoC;
using LinFu.Reflection;

namespace CoreEx.Wcf.Common.Implementation
{
    [LoaderPlugin]
    public class ContainerPlugin : IContainerPlugin
    {
        private bool _initialized = false;
        
        public void BeginLoad(IServiceContainer target){}
        

        public void EndLoad(IServiceContainer target)
        {
            if (_initialized)
                return;
            
            var serviceContractResolver = target.GetService<ITypeResolver>("ServiceContractResolver");
            target.AddService("ServiceContractTypes", typeof(IList<Type>), new List<Type>(serviceContractResolver.GetTypes()));

            var knownTypeResolver = target.GetService<ITypeResolver>("KnownTypeResolver");           
            target.AddService("KnownTypes",typeof(IList<Type>), new List<Type>(knownTypeResolver.GetTypes()));

            var dataContractResolver = target.GetService<ITypeResolver>("DataContractResolver");
            target.AddService("DataContractTypes", typeof(IList<Type>),new List<Type>(dataContractResolver.GetTypes()));

            _initialized = true;

        }
    }
}
